package com.v1.admin.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.v1.lo.BaseLO;
import com.v1.lo.Statement;
import com.v1.model.Wish;

public class WishAction extends AdminAction {
	public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return mapping.findForward("wish");
	}

	public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer process = getInteger(request, "process", true);
		String processer = getString(request, "processer", true);
		Integer itemid = getInteger(request, "itemid", true);
		Integer categoryid = getInteger(request, "categoryid", true);

		BaseLO lo = (BaseLO) getBean("BaseLO");
		Wish model = new Wish();
		model.setCategoryid(categoryid);
		model.setItemid(itemid);
		model.setProcess(process);
		model.setProcesser(processer);

		int rowCount = lo.queryForCount(model, Statement.Wish_getWishCount);
		if (rowCount != 0) {
			Integer pageNo = getInteger(request, "page", 1);
			model.init(rowCount, pageNo);
			List<Wish> wishs = lo.queryForList(model, Statement.Wish_getWish);
			setAttribute(request, "wishs", wishs);
			setAttribute(request, "pageinfo", model);
		}
		return mapping.findForward("wish");
	}

	public ActionForward process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer step = getInteger(request, "step", true);
		Integer commentid = getInteger(request, "commentid", true);

		BaseLO lo = (BaseLO) getBean("BaseLO");
		Wish model = new Wish();
		model.setCommentid(commentid);
		model.setProcess(step);
		String name = getString(request, "name");
		model.setProcesser(name);
		try {
			lo.update(model, Statement.Wish_setWish);
			setAttribute(request, "message", "ok, done.");
		} catch (Exception e) {
			log.debug(e.getMessage(), e);
			setAttribute(request, "message", "ops." + e.getMessage());
		}
		return search(mapping, form, request, response);
	}
}
